﻿using UnityEngine;
using System.Collections;

public class _Meteor : MonoBehaviour {

int id = 75;
private float counter;
		
	void Awake()
	{		
		this.gameObject.AddComponent("MeshRenderer");
        this.gameObject.AddComponent("MeshFilter");	
		//this.gameObject.AddComponent("BoxCollider");
	}
	
	// Use this for initialization
	void Start () {
	    Mesh mesh = Quad.Create(0.5f, 0.5f);

        this.gameObject.GetComponent<MeshFilter>().mesh = mesh;
        this.gameObject.GetComponent<MeshRenderer>().material = AtlasManager.globalMaterial;
		
		//this.gameObject.GetComponent<BoxCollider>().isTrigger = true;

		
        this.gameObject.GetComponent<MeshFilter>().mesh.uv = new Vector2[]
		{
			new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMax),
			new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMax),
			new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMin),
			new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMin)
		};
	}
	
	// Update is called once per frame
	void Update () 
	{		
		if(counter > 2)
		{
			transform.Translate(0.0f,-0.1f,0.0f);
		}
		else counter += Time.deltaTime;
		
		if(this.transform.position.y < -8)
		{
			Destroy(this.gameObject);	
		}
	}
	
	void OnTriggerEnter(Collider other)
	{
		if(other.gameObject.tag =="Jogador")
		{
			
			SceneManager.PlayerDead = true;
			Player.MoreuAs = TimeCounter.Minutos;
			Destroy(this.gameObject);
		}
	}
}
